{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "442bd0b9",
   "metadata": {},
   "source": [
    "##    课后作业(一)----总结字典的其他方法\n",
    ">请大家实践：\n",
    ">> 1. 使用help查看字典的其他方法\n",
    ">> 2. 尝试每一种方法的使用并实践\n",
    ">> 3. 请大家用表格记录每一种方法的如何使用、注意事项、使用结果\n",
    "\n",
    "* 示例：\n",
    "\n",
    "| 字典的方法      | Description | 具体使用|\n",
    "| ----------- | ----------- |---------- |\n",
    "| pop()      | 给定一个存在的key，可以进行对应成员(key及value)的删除 |D.pop(k[,d]) -> v   |\n",
    "| popitem()   | ....        | .....  |\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7222eca7",
   "metadata": {},
   "source": [
    "#### 明确字典的概念\n",
    ">字典是另一种可变容器模型，且可存储任意类型对象。  \n",
    ">字典的每个键值 key=>value 对用冒号 : 分割，每个对之间用逗号(,)分割，整个字典包括在花括号 {} 中 ,格式如下所示：   \n",
    ">d = {key1 : value1, key2 : value2, key3 : value3 }请尝试使用和学习字典的方法   \n",
    ">键必须是唯一的，但值则不必。   \n",
    ">值可以取任何数据类型，但键必须是不可变的，如字符串，数字。   \n",
    "```\n",
    "一个简单的字典实例：\n",
    "dict = {'name': 'tululu', 'likes': '阿巴阿巴', 'url': 'www.python.org'}\n",
    "也可如此创建字典：\n",
    "dict1 = { 'abc': 287 }\n",
    "dict2 = { 'abc': 233, 99: 1099 }\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "515ba8c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 直接按照字典的格式创建 ： {key1：value1，key2：value2，...}\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "thisdict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f3511cd6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'model': '911', 'year': 1963}\n"
     ]
    }
   ],
   "source": [
    "# 也可使用 dict() 构造函数创建新的字典：\n",
    "thisdict = dict(brand=\"Porsche\", model=\"911\", year=1963)\n",
    "# 请注意，关键字不是字符串字面量\n",
    "# 请注意，使用了等号而不是冒号来赋值\n",
    "print(thisdict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f0a8794b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 还可以字典数据增加的方式：新建空字典 \n",
    "# dict_name={}\n",
    "# dict_name[key1]=value1...  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "16667eda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "911\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#1.访问字典里的值\n",
    "#A.可以通过在方括号内引用其键名来访问字典的项目：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "x = thisdict[\"model\"]\n",
    "print(x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cf1cf019",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Porsche\n"
     ]
    }
   ],
   "source": [
    "#B.有一个名为 get() 的方法会给你相同的结果：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "x = thisdict.get(\"brand\")\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9fa8bf37",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method_descriptor:\n",
      "\n",
      "get(self, key, default=None, /)\n",
      "    Return the value for key if key is in the dictionary, else default.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.get)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "be489b72",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Yes, 'model' is one of the keys in the thisdict dictionary\n"
     ]
    }
   ],
   "source": [
    "#  1.检查键是否存在\n",
    "# 要确定字典中是否存在指定的键，请使用 in 关键字：\n",
    "# 实例\n",
    "# 检查字典中是否存在 \"model\"：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "if \"model\" in thisdict:\n",
    "  print(\"Yes, 'model' is one of the keys in the thisdict dictionary\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9e50d45c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'model': 119, 'year': 2021}\n"
     ]
    }
   ],
   "source": [
    "# 2.更改值\n",
    "# 您可以通过引用其键名来更改特定项的值：\n",
    "# 把 \"year\" 改为 2021：\n",
    "# 把\"model\" 改为119：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "thisdict[\"year\"] = 2021\n",
    "thisdict[\"model\"] = 119\n",
    "print(thisdict)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d33f4eef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "brand\n",
      "model\n",
      "year\n"
     ]
    }
   ],
   "source": [
    "# 遍历字典——使用 for 循环遍历字典。\n",
    "# 循环遍历字典时，返回值是字典的键，但也有返回值的方法。\n",
    "# 实例\n",
    "# 逐个打印字典中的所有键名：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "for key in thisdict:\n",
    "  print(key)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ba948e20",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "White\n"
     ]
    }
   ],
   "source": [
    "# setdefault() 方法使用指定的键返回项目的值。\n",
    "# 如果键不存在，则插入这个具有指定值的键。请看下面的例子。\n",
    "thisdict = {\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "x = thisdict.setdefault(\"color\", \"White\")\n",
    "# 获取 \"color\" 项的值，如果 \"color\" 项不存在，则插入值为 \"white\" 的 \"color\"：\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7c2748fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method_descriptor:\n",
      "\n",
      "setdefault(self, key, default=None, /)\n",
      "    Insert key with a value of default if key is not in the dictionary.\n",
      "    \n",
      "    Return the value for key if key is in the dictionary, else default.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.setdefault)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b208c7dd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['brand', 'model', 'year'])\n"
     ]
    }
   ],
   "source": [
    "# keys() 方法返回 view 对象。返回包含字典键的列表。这个视图对象包含列表形式的字典键。\n",
    "# 该视图对象会反映字典的任何改变，请看下面的例子。\n",
    "# 返回键：\n",
    "\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "\n",
    "x = thisdict.keys()\n",
    "\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c22043c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Porsche\n",
      "911\n",
      "1963\n"
     ]
    }
   ],
   "source": [
    "# 实例\n",
    "# 逐个打印字典中的所有值：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "for x in thisdict:\n",
    "  print(thisdict[x])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2b00a099",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Porsche\n",
      "911\n",
      "1963\n"
     ]
    }
   ],
   "source": [
    "#使用 .values() 函数返回字典的值：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "for x in thisdict.values():\n",
    "  print(x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cbf74e51",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method_descriptor:\n",
      "\n",
      "values(...)\n",
      "    D.values() -> an object providing a view on D's values\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f4346ba7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'key1': 0, 'key2': 0, 'key3': 0}\n"
     ]
    }
   ],
   "source": [
    "# fromkeys() 方法返回具有指定键和值的字典。\n",
    "x = ('key1', 'key2', 'key3')\n",
    "y = 0\n",
    "\n",
    "thisdict = dict.fromkeys(x, y)\n",
    "\n",
    "print(thisdict)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "35eb7c33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function fromkeys:\n",
      "\n",
      "fromkeys(iterable, value=None, /) method of builtins.type instance\n",
      "    Create a new dictionary with keys from iterable and values set to value.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.fromkeys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8bc8b937",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "brand Porsche\n",
      "model 911\n",
      "year 1963\n"
     ]
    }
   ],
   "source": [
    "#通过使用 items() 函数遍历键和值：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "for x, y in thisdict.items():\n",
    "  print(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d065e883",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method_descriptor:\n",
      "\n",
      "items(...)\n",
      "    D.items() -> a set-like object providing a view on D's items\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.items)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "49deeeaa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "# 字典长度\n",
    "# 要确定字典有多少项目（键值对），请使用 len() 方法。\n",
    "# 实例\n",
    "# 打印字典中的项目数：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "\n",
    "print(len(thisdict))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a2dc5f91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function len in module builtins:\n",
      "\n",
      "len(obj, /)\n",
      "    Return the number of items in a container.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(len)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8d894736",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'model': '911', 'year': 1963, 'color': 'red'}\n"
     ]
    }
   ],
   "source": [
    "# 3.添加项目\n",
    "# 通过使用新的索引键并为其赋值，可以将项目添加到字典中：\n",
    "# 实例\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "thisdict[\"color\"] = \"red\"\n",
    "print(thisdict)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "058c6516",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'year': 1963}\n"
     ]
    }
   ],
   "source": [
    "# 4.删除项目\n",
    "# 有几种方法可以从字典中删除项目：\n",
    "# pop() 方法删除具有指定键名的项：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "thisdict.pop(\"model\")\n",
    "print(thisdict)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d064da19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method_descriptor:\n",
      "\n",
      "pop(...)\n",
      "    D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n",
      "    If key is not found, d is returned if given, otherwise KeyError is raised\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f7c1e7a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'model': '911'}\n"
     ]
    }
   ],
   "source": [
    "# popitem() 方法删除最后插入的项目\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "thisdict.popitem()\n",
    "print(thisdict)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "9fed540e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method_descriptor:\n",
      "\n",
      "popitem(self, /)\n",
      "    Remove and return a (key, value) pair as a 2-tuple.\n",
      "    \n",
      "    Pairs are returned in LIFO (last-in, first-out) order.\n",
      "    Raises KeyError if the dict is empty.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.popitem)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d0c99ddf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'year': 1963}\n"
     ]
    }
   ],
   "source": [
    "# del 关键字删除具有指定键名的项目：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "del thisdict[\"model\"]\n",
    "print(thisdict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "c2c4fa17",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'thisdict' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-27-330f6c731e3f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      7\u001b[0m \u001b[1;32mdel\u001b[0m \u001b[0mthisdict\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mthisdict\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#this 会导致错误，因为 \"thisdict\" 不再存在。\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'thisdict' is not defined"
     ]
    }
   ],
   "source": [
    "# del 关键字也可以完全删除字典：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "del thisdict\n",
    "\n",
    "print(thisdict) #this 会导致错误，因为 \"thisdict\" 不再存在。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5ac0d3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# clear() 关键字清空字典：\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "thisdict.clear()\n",
    "print(thisdict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "e11d00a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method_descriptor:\n",
      "\n",
      "clear(...)\n",
      "    D.clear() -> None.  Remove all items from D.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.clear)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f3c138fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'model': '911', 'year': 1963}\n"
     ]
    }
   ],
   "source": [
    "# 复制字典\n",
    "# 不能通过键入 dict2 = dict1 来复制字典，因为：dict2 只是对 dict1 的引用，而 dict1 中的更改也将自动在 dict2 中进行。\n",
    "# 有一些方法可以进行复制，一种方法是使用内建的字典方法 copy()。\n",
    "# 使用 copy() 方法来复制字典：\n",
    "\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "mydict = thisdict.copy()\n",
    "print(mydict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "cb8b86a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'model': '911', 'year': 1963}\n"
     ]
    }
   ],
   "source": [
    "# 制作副本的另一种方法是使用内建方法 dict()\n",
    "# 使用 dict() 方法创建字典的副本：\n",
    "\n",
    "thisdict ={\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "mydict = dict(thisdict)\n",
    "print(mydict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a1156cbc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'child1': {'name': 'Phoebe Adele', 'year': 2002}, 'child2': {'name': 'Jennifer Katharine', 'year': 1996}, 'child3': {'name': 'Rory John', 'year': 1999}}\n"
     ]
    }
   ],
   "source": [
    "# 嵌套字典\n",
    "# 词典也可以包含许多词典，这被称为嵌套词典。\n",
    "# 实例\n",
    "# 创建包含三个字典的字典：\n",
    "\n",
    "myfamily = {\n",
    "  \"child1\" : {\n",
    "    \"name\" : \"Phoebe Adele\",\n",
    "    \"year\" : 2002\n",
    "  },\n",
    "  \"child2\" : {\n",
    "    \"name\" : \"Jennifer Katharine\",\n",
    "    \"year\" : 1996\n",
    "  },\n",
    "  \"child3\" : {\n",
    "    \"name\" : \"Rory John\",\n",
    "    \"year\" : 1999\n",
    "  }\n",
    "}\n",
    "print(myfamily)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5a1e5ac5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'child1': {'name': 'Phoebe Adele', 'year': 2002}, 'child2': {'name': 'Jennifer Katharine', 'year': 1996}, 'child3': {'name': 'Rory John', 'year': 1999}}\n"
     ]
    }
   ],
   "source": [
    "# 或者嵌套三个已经作为字典存在的字典：\n",
    "# 实例\n",
    "# 创建三个字典，然后创建一个包含其他三个字典的字典：\n",
    "child1 = {\n",
    "  \"name\" : \"Phoebe Adele\",\n",
    "  \"year\" : 2002\n",
    "}\n",
    "child2 = {\n",
    "  \"name\" : \"Jennifer Katharine\",\n",
    "  \"year\" : 1996\n",
    "}\n",
    "child3 = {\n",
    "  \"name\" : \"Rory John\",\n",
    "  \"year\" : 1999\n",
    "}\n",
    "\n",
    "myfamily = {\n",
    "  \"child1\" : child1,\n",
    "  \"child2\" : child2,\n",
    "  \"child3\" : child3\n",
    "}\n",
    "\n",
    "print(myfamily)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "71dc5572",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'brand': 'Porsche', 'model': '911', 'year': 1963, 'color': 'White'}\n"
     ]
    }
   ],
   "source": [
    "# Python 字典 update() 方法\n",
    "# 向字典插入项目：\n",
    "thisdict = {\n",
    "  \"brand\": \"Porsche\",\n",
    "  \"model\": \"911\",\n",
    "  \"year\": 1963\n",
    "}\n",
    "\n",
    "thisdict.update({\"color\": \"White\"})\n",
    "\n",
    "print(thisdict)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "7e87f4e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method_descriptor:\n",
      "\n",
      "update(...)\n",
      "    D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.\n",
      "    If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]\n",
      "    If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v\n",
      "    In either case, this is followed by: for k in F:  D[k] = F[k]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(dict.update)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "770a1f09",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "## [字典方法](https://docs.python.org/zh-cn/3/library/stdtypes.html#typesmapping)\n",
    "\n",
    "Python 提供一组可以在字典上使用的内建方法。\n",
    "\n",
    ">[claer()链接](\"https://www.w3school.com.cn/python/ref_dictionary_clear.asp\")\n",
    ">[copy()链接](\"https://www.w3school.com.cn/python/ref_dictionary_copy.asp\")\n",
    ">[fromkeys()链接](\"https://www.w3school.com.cn/python/ref_dictionary_fromkeys.asp\")\n",
    ">[get()链接](\"https://www.w3school.com.cn/python/ref_dictionary_get.asp\")\n",
    ">[items()链接](\"https://www.w3school.com.cn/python/ref_dictionar)\n",
    ">[keys()链接](\"https://www.w3school.com.cn/python/ref_dictionary_keys.asp\")\n",
    ">[pop()链接](\"https://www.w3school.com.cn/python/ref_dictionary_pop.asp\")\n",
    ">[popitem()链接](\"https://www.w3school.com.cn/python/ref_dictionary_popitem.asp\")\n",
    ">[setdefault()链接](\"https://www.w3school.com.cn/python/ref_dictionary_setdefault.asp\")\n",
    ">[update()链接](\"https://www.w3school.com.cn/python/ref_dictionary_update.asp\")\n",
    ">[values()链接](\"https://www.w3school.com.cn/python/ref_dictionary_values.asp\")\n",
    "<table>\n",
    "<tr>\n",
    "<th>字典的方法</th>\n",
    "<th>描述</th>\n",
    "<th>具体注意事项</th>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>clear()</td>\n",
    "<td>删除字典中的所有元素</td>\n",
    "<td>clear()移除字典中的所有元素。</td>\n",
    "<th></th>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>copy()</td>\n",
    "<td>返回字典的副本</td>\n",
    "<td>copy()返回原字典的浅拷贝</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>fromkeys()</td>\n",
    "<td>返回拥有指定键和值的字典</td>    \n",
    "<td>fromkeys() 是一个返回新字典的类方法。 value 默认为 None。所有值都只引用一个单独的实例，因此让 value 成为一个可变对象例如空列表通常是没有意义的。要获取不同的值，请改用字典推导式。</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>get()</td>\n",
    "<td>返回指定键的值</td>\n",
    "<td>get(key[, default])如果 key 存在于字典中则返回 key 的值，否则返回 default。如果 default 未给出则默认为 None，因而此方法绝不会引发 KeyError</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>items()</td>\n",
    "<td>返回包含每个键值对的元组的列表</td>\n",
    "<td>items()返回由字典项 ((键, 值) 对) 组成的一个新视图。</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>keys()</td>\n",
    "<td>返回包含字典键的列表</td>\n",
    "<td>keys(...)返回由字典键组成的一个新视图。</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>pop()</td>\n",
    "<td>删除拥有指定键的元素</td>\n",
    "<td>pop(key[, default])如果 key 存在于字典中则将其移除并返回其值，否则返回 default。\n",
    "    如果 default 未给出且 key 不存在于字典中，则会引发 KeyError。</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>popitem()</td>\n",
    "<td>删除最后插入的键值对</td>\n",
    "<td>从字典中移除并返回一个 (键, 值) 对。 键值对会按 LIFO 的顺序被返回。\n",
    "    popitem() 适用于对字典进行消耗性的迭代，这在集合算法中经常被使用。\n",
    "    如果字典为空，调用 popitem() 将引发 KeyError.</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>setdefault()</td>\n",
    "<td>返回指定键的值。如果该键不存在，则插入具有指定值的键。</td>\n",
    "<td>如果字典存在键 key ，返回它的值。\n",
    "    如果不存在，插入值为 default 的键 key ，并返回 default 。 default 默认为 None。</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>update()</td>\n",
    "<td>使用指定的键值对字典进行更新</td>\n",
    "<td>update([other])使用来自 other 的键值对更新字典，覆盖原有的键。返回 None。\n",
    "    update() 接受另一个字典对象，或者一个包含键值对（以长度为二的元组或其他可迭代对象表示）的可迭代对象。\n",
    "    如果给出了关键字参数，则会以其所指定的键值对更新字典: d.update(red=1, blue=2)。</td>\n",
    "</tr>\n",
    "\n",
    "<tr>\n",
    "<td>values()</td>\n",
    "<td>返回字典中所有值的列表</td>\n",
    "<td>values()\n",
    "    两个 dict.values() 视图之间的相等性比较将总是返回 False。\n",
    "    这在 dict.values() 与其自身比较时也同样适用:</td>\n",
    "</tr>\n",
    "</table>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "980c60ce",
   "metadata": {},
   "source": [
    "## 课后实践:\n",
    "> 1. 请找出 id 为 'B0HGD588HJ' 的 信息(第一题如上)\n",
    "> 2. 请找出所有的 pois 中的字典元素 的 id，存到一个id列表中\n",
    "> 3. 请找出所有的 pois 中的字典元素 的 name，存到一个 id 列表中\n",
    "> 4. 请找出所有的 name 以及 location  做一个字典 （name_dict = {name1:location1 , name2:location2...}）\n",
    "> 5. 请找出所有 含有 'tel' 的元素 \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "887606cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "广州南方学院 = {'status': '1',\n",
    " 'regeocode': {'roads': [{'id': '020F49F0050461206',\n",
    "    'location': '113.678,23.6284',\n",
    "    'direction': '北',\n",
    "    'name': '博学路',\n",
    "    'distance': '7.63232'},\n",
    "   {'id': '020F49F0050462229',\n",
    "    'location': '113.679,23.6245',\n",
    "    'direction': '北',\n",
    "    'name': '老虎形街',\n",
    "    'distance': '445.159'},\n",
    "   {'id': '020F49F0050462451',\n",
    "    'location': '113.677,23.6347',\n",
    "    'direction': '南',\n",
    "    'name': '中山路',\n",
    "    'distance': '708.299'}],\n",
    "  'roadinters': [{'second_name': '中山路',\n",
    "    'first_id': '020F49F0050461206',\n",
    "    'second_id': '020F49F0050462451',\n",
    "    'location': '113.676794,23.634661',\n",
    "    'distance': '708.299',\n",
    "    'first_name': '博学路',\n",
    "    'direction': '南'}],\n",
    "  'formatted_address': '广东省广州市从化区温泉镇博学路',\n",
    "  'addressComponent': {'city': '广州市',\n",
    "   'province': '广东省',\n",
    "   'adcode': '440117',\n",
    "   'district': '从化区',\n",
    "   'towncode': '440117100000',\n",
    "   'streetNumber': {'number': '24号',\n",
    "    'location': '113.677267,23.629149',\n",
    "    'direction': '西北',\n",
    "    'distance': '129.943',\n",
    "    'street': '博学路'},\n",
    "   'country': '中国',\n",
    "   'township': '温泉镇',\n",
    "   'businessAreas': [[]],\n",
    "   'building': {'name': [], 'type': []},\n",
    "   'neighborhood': {'name': [], 'type': []},\n",
    "   'citycode': '020'},\n",
    "  'aois': [],\n",
    "  'pois': [{'id': 'B0FFG4TAF2',\n",
    "    'direction': '东南',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉镇乌土村松浪队5号(近博学路)',\n",
    "    'poiweight': '0.237309',\n",
    "    'name': '广州南方公寓',\n",
    "    'location': '113.678983,23.627778',\n",
    "    'distance': '102.617',\n",
    "    'tel': '13622768437',\n",
    "    'type': '商务住宅;住宅区;住宅小区'},\n",
    "   {'id': 'B0H6FA18J5',\n",
    "    'direction': '东南',\n",
    "    'businessarea': [],\n",
    "    'address': '从莞深高速(广州南方学院南侧)',\n",
    "    'poiweight': '0.223065',\n",
    "    'name': '保利半山花园',\n",
    "    'location': '113.679358,23.627672',\n",
    "    'distance': '139.054',\n",
    "    'tel': [],\n",
    "    'type': '商务住宅;住宅区;住宅区'},\n",
    "   {'id': 'B00140TWHT',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '笃行路2',\n",
    "    'poiweight': '0.157653',\n",
    "    'name': '教工住宅1号',\n",
    "    'location': '113.678490,23.630432',\n",
    "    'distance': '222.658',\n",
    "    'tel': [],\n",
    "    'type': '商务住宅;住宅区;住宅小区'},\n",
    "   {'id': 'B0FFHRJDM9',\n",
    "    'direction': '东南',\n",
    "    'businessarea': [],\n",
    "    'address': '中大南方学院南门1号',\n",
    "    'poiweight': '0.256152',\n",
    "    'name': '中南公寓',\n",
    "    'location': '113.680349,23.627573',\n",
    "    'distance': '231.723',\n",
    "    'tel': '13711245345',\n",
    "    'type': '商务住宅;住宅区;住宅小区'},\n",
    "   {'id': 'B0HGD588HJ',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼4号',\n",
    "    'location': '113.677460,23.630490',\n",
    "    'distance': '242.901',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0FFHZH0IK',\n",
    "    'direction': '西北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路广州南方学院综合楼内',\n",
    "    'poiweight': '0.17934',\n",
    "    'name': '地下铁',\n",
    "    'location': '113.677941,23.629029',\n",
    "    'distance': '74.1376',\n",
    "    'tel': [],\n",
    "    'type': '餐饮服务;冷饮店;冷饮店'},\n",
    "   {'id': 'B0HGDU76L2',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院2号实验楼',\n",
    "    'location': '113.678211,23.630956',\n",
    "    'distance': '280.003',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0FFKP838K',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路25',\n",
    "    'poiweight': '0.191742',\n",
    "    'name': '教学楼3号(外国语学院)',\n",
    "    'location': '113.677247,23.630947',\n",
    "    'distance': '298.093',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;高等院校'},\n",
    "   {'id': 'B0HGDU8NLD',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路附近',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院1号实验楼',\n",
    "    'location': '113.678215,23.631370',\n",
    "    'distance': '326.007',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HGD58UTU',\n",
    "    'direction': '西北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路',\n",
    "    'poiweight': '0.191229',\n",
    "    'name': '广州南方学院2号教学楼',\n",
    "    'location': '113.677060,23.631346',\n",
    "    'distance': '346.352',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B00140MR9A',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号',\n",
    "    'poiweight': '0.450402',\n",
    "    'name': '广州南方学院',\n",
    "    'location': '113.679262,23.632583',\n",
    "    'distance': '471.564',\n",
    "    'tel': '020-87828988;020-61787331',\n",
    "    'type': '科教文化服务;学校;高等院校'},\n",
    "   {'id': 'B0HGDU92JD',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': [],\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼1号',\n",
    "    'location': '113.677077,23.631783',\n",
    "    'distance': '391.548',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HGD592BJ',\n",
    "    'direction': '东北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道886号广州南方学院内',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院综合楼',\n",
    "    'location': '113.680117,23.631544',\n",
    "    'distance': '392.731',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0FFKP81F0',\n",
    "    'direction': '西北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路19号附近',\n",
    "    'poiweight': '0.191742',\n",
    "    'name': '教学楼1号(文学与传媒学院)',\n",
    "    'location': '113.676866,23.631736',\n",
    "    'distance': '393.93',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
    "   {'id': 'B0FFLBEOND',\n",
    "    'direction': '东北',\n",
    "    'businessarea': [],\n",
    "    'address': '从莞深高速(广州南方学院)',\n",
    "    'poiweight': '0.190963',\n",
    "    'name': '聚贤楼10号',\n",
    "    'location': '113.681253,23.631036',\n",
    "    'distance': '418.51',\n",
    "    'tel': [],\n",
    "    'type': '商务住宅;住宅区;宿舍'},\n",
    "   {'id': 'B0FFH6K3U9',\n",
    "    'direction': '西北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉镇温泉大道882号广州南方学院H7栋1-5层',\n",
    "    'poiweight': '0.254885',\n",
    "    'name': '广州中大南方招待所',\n",
    "    'location': '113.676330,23.631332',\n",
    "    'distance': '378.102',\n",
    "    'tel': '020-61787222',\n",
    "    'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
    "   {'id': 'B0HGD58NF8',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号广州南方学院新综合楼2层',\n",
    "    'poiweight': '0.191229',\n",
    "    'name': '广州南方学院达人书院',\n",
    "    'location': '113.679041,23.632392',\n",
    "    'distance': '446.366',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
    "   {'id': 'B0FFKUVYWV',\n",
    "    'direction': '东北',\n",
    "    'businessarea': [],\n",
    "    'address': '保利桃花源',\n",
    "    'poiweight': '0.273168',\n",
    "    'name': '广州和风庭阿七度假别墅',\n",
    "    'location': '113.681736,23.630569',\n",
    "    'distance': '424.35',\n",
    "    'tel': '18681565305',\n",
    "    'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
    "   {'id': 'B0HGDU99RM',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号广州南方学院内',\n",
    "    'poiweight': '0.257947',\n",
    "    'name': '广州南方学院图书馆',\n",
    "    'location': '113.679177,23.632762',\n",
    "    'distance': '489.331',\n",
    "    'tel': '020-61787368;020-61787371',\n",
    "    'type': '科教文化服务;图书馆;图书馆'},\n",
    "   {'id': 'B0HGDU92JC',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路附近',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院4号实验楼',\n",
    "    'location': '113.679963,23.632652',\n",
    "    'distance': '498.883',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0FFL7C054',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉镇博学路882号(广州南方学院商业中心1层)',\n",
    "    'poiweight': '0.317505',\n",
    "    'name': '广州U优森特酒店',\n",
    "    'location': '113.679226,23.632528',\n",
    "    'distance': '464.819',\n",
    "    'tel': '15813395296',\n",
    "    'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
    "   {'id': 'B0FFG8CSEK',\n",
    "    'direction': '东北',\n",
    "    'businessarea': [],\n",
    "    'address': '从莞深高速(广州南方学院)',\n",
    "    'poiweight': '0.185371',\n",
    "    'name': 'L5员工宿舍',\n",
    "    'location': '113.682583,23.631487',\n",
    "    'distance': '554.129',\n",
    "    'tel': [],\n",
    "    'type': '商务住宅;住宅区;宿舍'},\n",
    "   {'id': 'B0HGD58FR2',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '广州南方学院',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼9号',\n",
    "    'location': '113.679747,23.633032',\n",
    "    'distance': '532.163',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HG5Z9JNK',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路',\n",
    "    'poiweight': '0.221553',\n",
    "    'name': '广州南方学院教学楼7号',\n",
    "    'location': '113.678600,23.633330',\n",
    "    'distance': '544.868',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HGD599JM',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号广州南方学院',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院第11教学楼',\n",
    "    'location': '113.680037,23.633173',\n",
    "    'distance': '556.036',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0GUJYPEG2',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号广州南方学院内博学路6号之3',\n",
    "    'poiweight': '0.216026',\n",
    "    'name': '怒烤烤串(从化店)',\n",
    "    'location': '113.677160,23.632910',\n",
    "    'distance': '510.112',\n",
    "    'tel': [],\n",
    "    'type': '餐饮服务;中餐厅;特色/地方风味餐厅'},\n",
    "   {'id': 'B0HGDU6Z41',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼6号',\n",
    "    'location': '113.678424,23.633710',\n",
    "    'distance': '586.331',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HGD580NZ',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路7号附近',\n",
    "    'poiweight': '0.285712',\n",
    "    'name': '广州南方学院惟贤门',\n",
    "    'location': '113.678437,23.633721',\n",
    "    'distance': '587.601',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;高等院校'},\n",
    "   {'id': 'B0HGDU7T1K',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '从莞深高速(广州南方学院)',\n",
    "    'poiweight': '0.191229',\n",
    "    'name': '广州南方学院教学楼10号',\n",
    "    'location': '113.680125,23.633492',\n",
    "    'distance': '592.504',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
    "   {'id': 'B0HGDU76L1',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '中山路与博学路交叉口东南150米',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼5号',\n",
    "    'location': '113.678046,23.633982',\n",
    "    'distance': '616.848',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'}]},\n",
    " 'info': 'OK',\n",
    " 'infocode': '10000'}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "dc6e473c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['status', 'regeocode', 'info', 'infocode'])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "广州南方学院.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0baff935",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['roads', 'roadinters', 'formatted_address', 'addressComponent', 'aois', 'pois'])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "广州南方学院['regeocode'].keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "cbb92c92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'id': 'B0FFG4TAF2',\n",
       "  'direction': '东南',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉镇乌土村松浪队5号(近博学路)',\n",
       "  'poiweight': '0.237309',\n",
       "  'name': '广州南方公寓',\n",
       "  'location': '113.678983,23.627778',\n",
       "  'distance': '102.617',\n",
       "  'tel': '13622768437',\n",
       "  'type': '商务住宅;住宅区;住宅小区'},\n",
       " {'id': 'B0H6FA18J5',\n",
       "  'direction': '东南',\n",
       "  'businessarea': [],\n",
       "  'address': '从莞深高速(广州南方学院南侧)',\n",
       "  'poiweight': '0.223065',\n",
       "  'name': '保利半山花园',\n",
       "  'location': '113.679358,23.627672',\n",
       "  'distance': '139.054',\n",
       "  'tel': [],\n",
       "  'type': '商务住宅;住宅区;住宅区'},\n",
       " {'id': 'B00140TWHT',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '笃行路2',\n",
       "  'poiweight': '0.157653',\n",
       "  'name': '教工住宅1号',\n",
       "  'location': '113.678490,23.630432',\n",
       "  'distance': '222.658',\n",
       "  'tel': [],\n",
       "  'type': '商务住宅;住宅区;住宅小区'},\n",
       " {'id': 'B0FFHRJDM9',\n",
       "  'direction': '东南',\n",
       "  'businessarea': [],\n",
       "  'address': '中大南方学院南门1号',\n",
       "  'poiweight': '0.256152',\n",
       "  'name': '中南公寓',\n",
       "  'location': '113.680349,23.627573',\n",
       "  'distance': '231.723',\n",
       "  'tel': '13711245345',\n",
       "  'type': '商务住宅;住宅区;住宅小区'},\n",
       " {'id': 'B0HGD588HJ',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院教学楼4号',\n",
       "  'location': '113.677460,23.630490',\n",
       "  'distance': '242.901',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0FFHZH0IK',\n",
       "  'direction': '西北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路广州南方学院综合楼内',\n",
       "  'poiweight': '0.17934',\n",
       "  'name': '地下铁',\n",
       "  'location': '113.677941,23.629029',\n",
       "  'distance': '74.1376',\n",
       "  'tel': [],\n",
       "  'type': '餐饮服务;冷饮店;冷饮店'},\n",
       " {'id': 'B0HGDU76L2',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院2号实验楼',\n",
       "  'location': '113.678211,23.630956',\n",
       "  'distance': '280.003',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0FFKP838K',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路25',\n",
       "  'poiweight': '0.191742',\n",
       "  'name': '教学楼3号(外国语学院)',\n",
       "  'location': '113.677247,23.630947',\n",
       "  'distance': '298.093',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;高等院校'},\n",
       " {'id': 'B0HGDU8NLD',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路附近',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院1号实验楼',\n",
       "  'location': '113.678215,23.631370',\n",
       "  'distance': '326.007',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0HGD58UTU',\n",
       "  'direction': '西北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路',\n",
       "  'poiweight': '0.191229',\n",
       "  'name': '广州南方学院2号教学楼',\n",
       "  'location': '113.677060,23.631346',\n",
       "  'distance': '346.352',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B00140MR9A',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉大道882号',\n",
       "  'poiweight': '0.450402',\n",
       "  'name': '广州南方学院',\n",
       "  'location': '113.679262,23.632583',\n",
       "  'distance': '471.564',\n",
       "  'tel': '020-87828988;020-61787331',\n",
       "  'type': '科教文化服务;学校;高等院校'},\n",
       " {'id': 'B0HGDU92JD',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': [],\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院教学楼1号',\n",
       "  'location': '113.677077,23.631783',\n",
       "  'distance': '391.548',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0HGD592BJ',\n",
       "  'direction': '东北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉大道886号广州南方学院内',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院综合楼',\n",
       "  'location': '113.680117,23.631544',\n",
       "  'distance': '392.731',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0FFKP81F0',\n",
       "  'direction': '西北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路19号附近',\n",
       "  'poiweight': '0.191742',\n",
       "  'name': '教学楼1号(文学与传媒学院)',\n",
       "  'location': '113.676866,23.631736',\n",
       "  'distance': '393.93',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       " {'id': 'B0FFLBEOND',\n",
       "  'direction': '东北',\n",
       "  'businessarea': [],\n",
       "  'address': '从莞深高速(广州南方学院)',\n",
       "  'poiweight': '0.190963',\n",
       "  'name': '聚贤楼10号',\n",
       "  'location': '113.681253,23.631036',\n",
       "  'distance': '418.51',\n",
       "  'tel': [],\n",
       "  'type': '商务住宅;住宅区;宿舍'},\n",
       " {'id': 'B0FFH6K3U9',\n",
       "  'direction': '西北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉镇温泉大道882号广州南方学院H7栋1-5层',\n",
       "  'poiweight': '0.254885',\n",
       "  'name': '广州中大南方招待所',\n",
       "  'location': '113.676330,23.631332',\n",
       "  'distance': '378.102',\n",
       "  'tel': '020-61787222',\n",
       "  'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
       " {'id': 'B0HGD58NF8',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉大道882号广州南方学院新综合楼2层',\n",
       "  'poiweight': '0.191229',\n",
       "  'name': '广州南方学院达人书院',\n",
       "  'location': '113.679041,23.632392',\n",
       "  'distance': '446.366',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       " {'id': 'B0FFKUVYWV',\n",
       "  'direction': '东北',\n",
       "  'businessarea': [],\n",
       "  'address': '保利桃花源',\n",
       "  'poiweight': '0.273168',\n",
       "  'name': '广州和风庭阿七度假别墅',\n",
       "  'location': '113.681736,23.630569',\n",
       "  'distance': '424.35',\n",
       "  'tel': '18681565305',\n",
       "  'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
       " {'id': 'B0HGDU99RM',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉大道882号广州南方学院内',\n",
       "  'poiweight': '0.257947',\n",
       "  'name': '广州南方学院图书馆',\n",
       "  'location': '113.679177,23.632762',\n",
       "  'distance': '489.331',\n",
       "  'tel': '020-61787368;020-61787371',\n",
       "  'type': '科教文化服务;图书馆;图书馆'},\n",
       " {'id': 'B0HGDU92JC',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路附近',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院4号实验楼',\n",
       "  'location': '113.679963,23.632652',\n",
       "  'distance': '498.883',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0FFL7C054',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉镇博学路882号(广州南方学院商业中心1层)',\n",
       "  'poiweight': '0.317505',\n",
       "  'name': '广州U优森特酒店',\n",
       "  'location': '113.679226,23.632528',\n",
       "  'distance': '464.819',\n",
       "  'tel': '15813395296',\n",
       "  'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
       " {'id': 'B0FFG8CSEK',\n",
       "  'direction': '东北',\n",
       "  'businessarea': [],\n",
       "  'address': '从莞深高速(广州南方学院)',\n",
       "  'poiweight': '0.185371',\n",
       "  'name': 'L5员工宿舍',\n",
       "  'location': '113.682583,23.631487',\n",
       "  'distance': '554.129',\n",
       "  'tel': [],\n",
       "  'type': '商务住宅;住宅区;宿舍'},\n",
       " {'id': 'B0HGD58FR2',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '广州南方学院',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院教学楼9号',\n",
       "  'location': '113.679747,23.633032',\n",
       "  'distance': '532.163',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0HG5Z9JNK',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路',\n",
       "  'poiweight': '0.221553',\n",
       "  'name': '广州南方学院教学楼7号',\n",
       "  'location': '113.678600,23.633330',\n",
       "  'distance': '544.868',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0HGD599JM',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉大道882号广州南方学院',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院第11教学楼',\n",
       "  'location': '113.680037,23.633173',\n",
       "  'distance': '556.036',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0GUJYPEG2',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉大道882号广州南方学院内博学路6号之3',\n",
       "  'poiweight': '0.216026',\n",
       "  'name': '怒烤烤串(从化店)',\n",
       "  'location': '113.677160,23.632910',\n",
       "  'distance': '510.112',\n",
       "  'tel': [],\n",
       "  'type': '餐饮服务;中餐厅;特色/地方风味餐厅'},\n",
       " {'id': 'B0HGDU6Z41',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '温泉大道882',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院教学楼6号',\n",
       "  'location': '113.678424,23.633710',\n",
       "  'distance': '586.331',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'},\n",
       " {'id': 'B0HGD580NZ',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '博学路7号附近',\n",
       "  'poiweight': '0.285712',\n",
       "  'name': '广州南方学院惟贤门',\n",
       "  'location': '113.678437,23.633721',\n",
       "  'distance': '587.601',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;高等院校'},\n",
       " {'id': 'B0HGDU7T1K',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '从莞深高速(广州南方学院)',\n",
       "  'poiweight': '0.191229',\n",
       "  'name': '广州南方学院教学楼10号',\n",
       "  'location': '113.680125,23.633492',\n",
       "  'distance': '592.504',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       " {'id': 'B0HGDU76L1',\n",
       "  'direction': '北',\n",
       "  'businessarea': [],\n",
       "  'address': '中山路与博学路交叉口东南150米',\n",
       "  'poiweight': '0.221662',\n",
       "  'name': '广州南方学院教学楼5号',\n",
       "  'location': '113.678046,23.633982',\n",
       "  'distance': '616.848',\n",
       "  'tel': [],\n",
       "  'type': '科教文化服务;学校;学校'}]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "广州南方学院['regeocode']['pois']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9a075ff2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'id': 'B0HGD588HJ', 'direction': '北', 'businessarea': [], 'address': '博学路', 'poiweight': '0.221662', 'name': '广州南方学院教学楼4号', 'location': '113.677460,23.630490', 'distance': '242.901', 'tel': [], 'type': '科教文化服务;学校;学校'}\n"
     ]
    }
   ],
   "source": [
    "# 问题一\n",
    "pois_list = 广州南方学院['regeocode']['pois']\n",
    "for i in pois_list:\n",
    "    if i[\"id\"] == 'B0HGD588HJ':\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ecefb42e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "B0FFG4TAF2\n",
      "B0H6FA18J5\n",
      "B00140TWHT\n",
      "B0FFHRJDM9\n",
      "B0HGD588HJ\n",
      "B0FFHZH0IK\n",
      "B0HGDU76L2\n",
      "B0FFKP838K\n",
      "B0HGDU8NLD\n",
      "B0HGD58UTU\n",
      "B00140MR9A\n",
      "B0HGDU92JD\n",
      "B0HGD592BJ\n",
      "B0FFKP81F0\n",
      "B0FFLBEOND\n",
      "B0FFH6K3U9\n",
      "B0HGD58NF8\n",
      "B0FFKUVYWV\n",
      "B0HGDU99RM\n",
      "B0HGDU92JC\n",
      "B0FFL7C054\n",
      "B0FFG8CSEK\n",
      "B0HGD58FR2\n",
      "B0HG5Z9JNK\n",
      "B0HGD599JM\n",
      "B0GUJYPEG2\n",
      "B0HGDU6Z41\n",
      "B0HGD580NZ\n",
      "B0HGDU7T1K\n",
      "B0HGDU76L1\n"
     ]
    }
   ],
   "source": [
    "# 问题二\n",
    "for i in 广州南方学院['regeocode']['pois']:\n",
    "    print(i['id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5bb2e6a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方公寓\n",
      "保利半山花园\n",
      "教工住宅1号\n",
      "中南公寓\n",
      "广州南方学院教学楼4号\n",
      "地下铁\n",
      "广州南方学院2号实验楼\n",
      "教学楼3号(外国语学院)\n",
      "广州南方学院1号实验楼\n",
      "广州南方学院2号教学楼\n",
      "广州南方学院\n",
      "广州南方学院教学楼1号\n",
      "广州南方学院综合楼\n",
      "教学楼1号(文学与传媒学院)\n",
      "聚贤楼10号\n",
      "广州中大南方招待所\n",
      "广州南方学院达人书院\n",
      "广州和风庭阿七度假别墅\n",
      "广州南方学院图书馆\n",
      "广州南方学院4号实验楼\n",
      "广州U优森特酒店\n",
      "L5员工宿舍\n",
      "广州南方学院教学楼9号\n",
      "广州南方学院教学楼7号\n",
      "广州南方学院第11教学楼\n",
      "怒烤烤串(从化店)\n",
      "广州南方学院教学楼6号\n",
      "广州南方学院惟贤门\n",
      "广州南方学院教学楼10号\n",
      "广州南方学院教学楼5号\n"
     ]
    }
   ],
   "source": [
    "# 问题三\n",
    "for i in 广州南方学院['regeocode']['pois']:\n",
    "    print(i['name'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "db120e64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'广州南方公寓': '113.678983,23.627778',\n",
       " '保利半山花园': '113.679358,23.627672',\n",
       " '教工住宅1号': '113.678490,23.630432',\n",
       " '中南公寓': '113.680349,23.627573',\n",
       " '广州南方学院教学楼4号': '113.677460,23.630490',\n",
       " '地下铁': '113.677941,23.629029',\n",
       " '广州南方学院2号实验楼': '113.678211,23.630956',\n",
       " '教学楼3号(外国语学院)': '113.677247,23.630947',\n",
       " '广州南方学院1号实验楼': '113.678215,23.631370',\n",
       " '广州南方学院2号教学楼': '113.677060,23.631346',\n",
       " '广州南方学院': '113.679262,23.632583',\n",
       " '广州南方学院教学楼1号': '113.677077,23.631783',\n",
       " '广州南方学院综合楼': '113.680117,23.631544',\n",
       " '教学楼1号(文学与传媒学院)': '113.676866,23.631736',\n",
       " '聚贤楼10号': '113.681253,23.631036',\n",
       " '广州中大南方招待所': '113.676330,23.631332',\n",
       " '广州南方学院达人书院': '113.679041,23.632392',\n",
       " '广州和风庭阿七度假别墅': '113.681736,23.630569',\n",
       " '广州南方学院图书馆': '113.679177,23.632762',\n",
       " '广州南方学院4号实验楼': '113.679963,23.632652',\n",
       " '广州U优森特酒店': '113.679226,23.632528',\n",
       " 'L5员工宿舍': '113.682583,23.631487',\n",
       " '广州南方学院教学楼9号': '113.679747,23.633032',\n",
       " '广州南方学院教学楼7号': '113.678600,23.633330',\n",
       " '广州南方学院第11教学楼': '113.680037,23.633173',\n",
       " '怒烤烤串(从化店)': '113.677160,23.632910',\n",
       " '广州南方学院教学楼6号': '113.678424,23.633710',\n",
       " '广州南方学院惟贤门': '113.678437,23.633721',\n",
       " '广州南方学院教学楼10号': '113.680125,23.633492',\n",
       " '广州南方学院教学楼5号': '113.678046,23.633982'}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 问题四\n",
    "name_dict = {}\n",
    "for i in  广州南方学院['regeocode']['pois']:\n",
    "    name_dict[i['name']] = i['location']\n",
    "name_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0badf78b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13622768437\n",
      "13711245345\n",
      "020-87828988;020-61787331\n",
      "020-61787222\n",
      "18681565305\n",
      "020-61787368;020-61787371\n",
      "15813395296\n"
     ]
    }
   ],
   "source": [
    "# 问题五\n",
    "for i in  广州南方学院['regeocode']['pois']:\n",
    "    if len(i['tel']) == 0:\n",
    "        continue\n",
    "    else:\n",
    "        print(i['tel'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b858463",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
